using System;
using System.Collections.Generic;
using UnityEngine;

namespace Features
{
    [CreateAssetMenu(fileName = "PropertyChange", menuName = "Features/改变属性", order = 2)]
    public class PropertyChange : Feature
    {
        public enum PropertyeType
        {
            Attack,
            HealPoint,
            Range,
            Speed,
            AtkSpeed,
            Defence
        }

        public PropertyeType TargetProperty;

        public enum TargetType
        {
            Self,
            SelfHero,
            EnemyHero
        }

        public TargetType TargetPawn = TargetType.Self;

        public float MutiValue = 1;
        public float AddValue;

        public override void CancleEffect(FeatureEventArgs args)
        {

        }

        public override void ExecuteEffect(FeatureEventArgs args)
        {
            var targetCard = args.pawn.Card;
            var target = args.pawn.Property;

            var playerHero = GridManager.instance.GetGridNode(1, 1);
            var computerHero = GridManager.instance.GetGridNode(6, 1);

            if (TargetPawn == TargetType.SelfHero)
            {
                targetCard = args.pawn.campIsSelf ? computerHero.Pawn.Card : playerHero.Pawn.Card;
                target = args.pawn.campIsSelf ? computerHero.Pawn.Property : playerHero.Pawn.Property;
            }
            if (TargetPawn == TargetType.EnemyHero)
            {
                targetCard = args.pawn.campIsSelf ? playerHero.Pawn.Card : computerHero.Pawn.Card;
                target = args.pawn.campIsSelf ? playerHero.Pawn.Property : computerHero.Pawn.Property;
            }

            string muti = MutiValue == 1 ? "" : MutiValue.ToString();
            string add = AddValue > 0 ? "+" + AddValue.ToString() : "-" + AddValue.ToString();
            if (AddValue == 0)
            {
                add = "";
            }

            switch (TargetProperty)
            {
                case PropertyeType.Attack:
                    /* if (IfForever && targetCard != null)
                    {
                        targetCard.Attack += AddValue;
                        targetCard.Attack *= MutiValue;
                    } */
                    target.Attack += AddValue;
                    target.Attack *= MutiValue;
                    SpriteTextManager.NewEffectText(muti + "攻击" + add, args.pawn.transform.position.x, args.pawn.transform.position.y, Color.red);
                    break;
                case PropertyeType.Defence:
                    /* if (IfForever && targetCard != null)
                    {
                        targetCard.Defence += AddValue;
                        targetCard.Defence *= MutiValue;
                    } */
                    target.Defence += AddValue;
                    target.Defence *= MutiValue;
                    SpriteTextManager.NewEffectText(muti + "防御" + add, args.pawn.transform.position.x, args.pawn.transform.position.y, Color.red);
                    break;
                case PropertyeType.HealPoint:
                    /* if (IfForever && targetCard != null)
                    {
                        targetCard.HealPoint += AddValue;
                        targetCard.HealPoint *= MutiValue;
                    } */
                    target.HealPoint += AddValue;
                    target.HealPoint *= MutiValue;
                    SpriteTextManager.NewEffectText(add, args.pawn.transform.position.x, args.pawn.transform.position.y, Color.green);
                    break;
                case PropertyeType.AtkSpeed:
                    /* if (IfForever && targetCard != null)
                    {
                        targetCard.AttackSpeed += AddValue;
                        targetCard.AttackSpeed *= MutiValue;
                    } */
                    target.AttackSpeed += AddValue;
                    target.AttackSpeed *= MutiValue;
                    //SpriteTextManager.NewEffectText(muti + "攻速" + add, args.pawn.transform.position.x, args.pawn.transform.position.y, Color.yellow);
                    break;
                case PropertyeType.Speed:
                    /* if (IfForever && targetCard != null)
                    {
                        targetCard.Speed += AddValue;
                        targetCard.Speed *= MutiValue;
                    } */
                    target.Speed += AddValue;
                    target.Speed *= MutiValue;
                    SpriteTextManager.NewEffectText(muti + "攻速" + add, args.pawn.transform.position.x, args.pawn.transform.position.y, Color.yellow);
                    break;
                case PropertyeType.Range:
                    /* if (IfForever && targetCard != null)
                    {
                        targetCard.Range += (int)AddValue;
                        targetCard.Range *= (int)MutiValue;
                    } */
                    target.Range += (int)AddValue;
                    target.Range *= (int)MutiValue;

                    SpriteTextManager.NewEffectText(muti + "射程" + add, args.pawn.transform.position.x, args.pawn.transform.position.y, Color.yellow);
                    break;
            }

        }

        public override string GetDescription()
        {
            string targetText = "自身";
            if (TargetPawn == TargetType.SelfHero)
            {
                targetText = "己方英雄";
            }
            if (TargetPawn == TargetType.EnemyHero)
            {
                targetText = "对方英雄";
            }
            string muti = MutiValue == 1 ? "" : MutiValue.ToString() + "倍";
            string add = AddValue > 0 ? "+" + AddValue.ToString() : "-" + AddValue.ToString();
            string text = "";
            switch (TargetProperty)
            {
                case PropertyeType.Attack:
                    text = muti + "攻击" + add;
                    break;
                case PropertyeType.Defence:
                    text = muti + "防御" + add;
                    break;
                case PropertyeType.HealPoint:
                    text = muti + "生命" + add;
                    break;
                case PropertyeType.AtkSpeed:
                    text = muti + "攻速" + add;
                    break;
                case PropertyeType.Speed:
                    text = muti + "攻速" + add;
                    break;
                case PropertyeType.Range:
                    text = muti + "射程" + add;
                    break;
            }
            return GetTriggerText() + targetText + "获得" + text;
        }

    }
}